import serial
import threading
import time
ser_alige = False
ser = None
def _open():
    global ser
    while True:
        if ser_alige:
            break
        else:
            try:
                ser = serial.Serial("COM1", 115200,timeout=0.5)
                time.sleep(1)
                break
            except Exception as e:
                print(e)

    while True:
        try:
            n = ser.read(10)
            if n:
                print(n)
        except Exception as e:
            print(e)

th = threading.Thread(target=_open).start()

